package com.example.init;

import com.example.HttpApp;
import com.example.util.PropertiesConfig;
import com.sun.net.httpserver.HttpServer;

import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class HttpServerApplication {

    private static  ExecutorService threadPool = null;

    public static void run(Class<?> classz,String[] args) throws IOException {
        Instant now = Instant.now();
        HttpServer server = HttpServer.create();
        ServerInit.init(server, classz.getPackage().getName(),args);
        threadPool = Executors.newFixedThreadPool(PropertiesConfig.getThreads());
        server.setExecutor(threadPool);
        server.start();
        System.out.println("启动完毕,线程数："+PropertiesConfig.getThreads()+";用时："+ Duration.between(now,Instant.now()).toMillis()+"ms");

    }
}
